#include "syscall.h"
#include "print.c"

#define THREADS			50
#define MAIN_TICKS		50

int lock;
int condition;

void thread() {
	int i;

	Acquire(lock);
	Wait(condition, lock);
	
	Exit(0);
}

int main()
{
	int i;
	int threadID;
	int printMsg[5];

	printString("-------------- Starting Test Maximum Fork --------------\n");

	lock = CreateLock();
	condition = CreateCondition();

	printMsg[0] = THREADS;
	printf("-> We are trying to fork %d threads...\n", printMsg);
	/* Forking threads */
	for (i = 1; i <= THREADS; i++){
		printf("-> Forking thread %d ...\n", &i);
		printMsg[0] = i;
		threadID = Fork(thread);
		if (threadID == -1) {
			printf("!!!! Forking thread attempt [%d] failed !!!!\n", printMsg);
		}
	}

	for (i = 0; i < MAIN_TICKS; i++) {
		Yield();
	}

	printString("-------------- Test Maximum Fork End --------------\n");
 
	Exit(0);
}
